﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using LayoutPlanning.Model;


namespace LayoutPlanning.Converters
{
    public class NegInfluenceExpander : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is double))
                return null;


            var enumerable = ViewModel.ViewModelLocator.Main.DeployedStations;
            var maxx = enumerable.Max(t => t.Position.X + t.NegativeInfluence/2);

            var minx = enumerable.Min(t => t.Position.X - t.NegativeInfluence/2);


            var maxy = enumerable.Max(t => t.Position.Y);
            var miny = enumerable.Where(y => Equals(y.Position.X, maxy)).Select(p => p.NegativeInfluence).Max();
            maxy += miny;
            return (double) value*340/(maxx - minx)/2;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}